<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="医院id" prop="hospitalId">
        <el-input
          v-model="queryParams.hospitalId"
          placeholder="请输入医院id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科室id" prop="departmentIds">
        <el-input
          v-model="queryParams.departmentIds"
          placeholder="请输入科室id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医师等级 1普通 2主治 3主任" prop="rankOfPhysician">
        <el-input
          v-model="queryParams.rankOfPhysician"
          placeholder="请输入医师等级 1普通 2主治 3主任"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医师姓名" prop="doctorName">
        <el-input
          v-model="queryParams.doctorName"
          placeholder="请输入医师姓名"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年限" prop="ageLimit">
        <el-input
          v-model="queryParams.ageLimit"
          placeholder="请输入年限"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医师资格证书" prop="doctorsCertificate">
        <el-input
          v-model="queryParams.doctorsCertificate"
          placeholder="请输入医师资格证书"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医师执业证书" prop="medicalPracticeCertificate">
        <el-input
          v-model="queryParams.medicalPracticeCertificate"
          placeholder="请输入医师执业证书"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总收入金额" prop="grossincomeAmount">
        <el-input
          v-model="queryParams.grossincomeAmount"
          placeholder="请输入总收入金额"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="诊金" prop="consultationFee">
        <el-input
          v-model="queryParams.consultationFee"
          placeholder="请输入诊金"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="medicList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="医师编号" align="center" prop="id" />
<!--      <el-table-column label="医院id" align="center" prop="hospitalId" />-->
<!--      <el-table-column label="科室id" align="center" prop="departmentIds" />-->
<!--      <el-table-column label="医师等级 1普通 2主治 3主任" align="center" prop="rankOfPhysician" />-->
      <el-table-column label="医师等级" align="center" prop="rankOfPhysician">
        <template #default="{ row }">
          <span v-if="row.rankOfPhysician==1">普通医生</span>
          <span v-if="row.rankOfPhysician==2">主治医生</span>
          <span v-if="row.rankOfPhysician==3">主任</span>
        </template>
      </el-table-column>
      <el-table-column label="医师姓名" align="center" prop="doctorName" />
<!--      <el-table-column label="年限" align="center" prop="ageLimit" />-->
<!--      <el-table-column label="医师资格证书" align="center" prop="doctorsCertificate" />-->
<!--      <el-table-column label="医师执业证书" align="center" prop="medicalPracticeCertificate" />-->
<!--      <el-table-column label="总收入金额" align="center" prop="grossincomeAmount" />-->
<!--      <el-table-column label="是否问诊【0-开启问诊 1-关闭问诊】" align="center" prop="status" />-->
      <el-table-column label="诊金" align="center" prop="consultationFee" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="selected(scope.row)">问诊</el-button>
<!--          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script setup name="Medic">
import {listMedic, getMedicUserId} from "@/api/doctor/medic";
import {useRoute, useRouter} from "vue-router";

const { proxy } = getCurrentInstance();

const medicList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const route = useRoute();
const router = useRouter();
const userId=ref(0)
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    hospitalId: null,
    departmentIds: null,
    rankOfPhysician: null,
    doctorName: null,
    ageLimit: null,
    doctorsCertificate: null,
    medicalPracticeCertificate: null,
    grossincomeAmount: null,
    status: null,
    consultationFee: null
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询医生列表列表 */
function getList() {
  loading.value = true;
  listMedic(queryParams.value).then(response => {
    medicList.value = response.data.rows;
    total.value = response.data.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    hospitalId: null,
    departmentIds: null,
    rankOfPhysician: null,
    doctorName: null,
    ageLimit: null,
    doctorsCertificate: null,
    medicalPracticeCertificate: null,
    grossincomeAmount: null,
    status: null,
    consultationFee: null
  };
  proxy.resetForm("medicRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}


function selected(row) {
  console.log(row.id)
  getMedicUserId(row.id).then(res=>{
    console.log(res)
     userId.value=res.data
    router.push({path:"/patient/index",query:{id:userId.value}})
  })

}






getList();
</script>
